package com.bnz.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.bnz.entity.Classes;
import com.bnz.entity.Student;
import com.bnz.service.IClassesService;
import com.bnz.service.IStudentService;
import com.bnz.vo.Message;
import com.bnz.vo.PageVo;
import com.bnz.vo.StudentVo;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xy
 * @date 2022/10/21
 */

@RestController
@RequestMapping("/student")
public class StudentController {
    @Reference
    private IStudentService studentService;
    @Reference
    private IClassesService classesService;

    @RequestMapping("/list")
    public Message list(@RequestBody StudentVo vo) {

        PageVo<Student> search = studentService.search(vo);
        return Message.ok().data("data", search);
    }

    @RequestMapping("/add")
    public Message add(@RequestBody Student student) {
        boolean update = studentService.save(student);
        return Message.ok().data("data", "添加学生成功！");
    }

    @RequestMapping("/delete/{id}")
    public Message delete(@PathVariable("id") String id) {
        boolean delete = studentService.removeById(id);
        return Message.ok().data("data", "删除学生成功！");
    }
    @RequestMapping("/class")
    public Message getClassList() {
        List<Classes> classes = classesService.list();
        return Message.ok().data("data", classes);
    }
    @RequestMapping("/batchdel/{sids}")
    public Message batchDel(@PathVariable("sids") String[] sids) {
          studentService.delete(sids);
        return Message.ok().data("data", "删除成功");
    }
    @RequestMapping("/modify")
    public Message modify(@RequestBody Student student) {
        int update = studentService.update(student);

        return Message.ok().data("data", "修改学生失败！");
    }
}
